<?php
namespace Web\Controller;
use Think\Controller;
class MixController extends Controller {
	/**
	 * 此控制器处理数据混合页面
	 * @return [type] [description]
	 */
   public function _initialize()  
    {  
        header("Content-Type: text/html; charset=utf-8");

    }
     public function _empty($name){
        //把所有城市的操作解析到city方法
        $this->nul($name);
    }
    
    //注意 city方法 本身是 protected 方法
    protected function nul($name){
        //和$name这个城市相关的处理
         echo "<h1>404</h1>";
         echo "没有这个地址:".$name;
    }
    /**
     * 显示聊天房间列表页面
     */
    public function show_chat_list(){
      if($_GET['search_kehu_name']){
        $where['kehu_name']=array('LIKE','%'.$_GET['search_kehu_name'].'%');
      }
      $where['state']=1;
      $res_data=M('lccdc')
                  ->alias('a')
                  ->join('bm_chat b ON a.chat_id=b.chat_id','LEFT')
                  ->join('bm_web_user_data c ON a.c_id=c.c_id','LEFT')
                  ->join('bm_shenqing d ON a.cd_id=d.cd_id','LEFT')
                  ->join('bm_search_data e ON a.data_id=e.data_id','LEFT')
                  ->where($where)
                  ->where('a.web_id='.session('user.web_id').' and b.chat_id >0')
                  ->order('lccdc_id desc')
                  ->group('lccdc_id')
               //  ->fetchsql(true)
                  ->select();
      unset($_SESSION['role']);
      $this->assign('apply',$res_data);
      $this->display();
    }
    /**
     * 显示聊天房间列表页面tream
     */
    public function show_chat_list_team(){
      if($_GET['search_kehu_name']){
        $where['kehu_name']=array('LIKE','%'.$_GET['search_kehu_name'].'%');
      }
      $res_data=M('lccdc')
                  ->alias('a')
                  ->join('bm_chat b ON a.chat_id=b.chat_id','LEFT')
                  ->join('bm_web_user_data c ON a.c_id=c.c_id','LEFT')
                  ->join('bm_shenqing d ON a.cd_id=d.cd_id','LEFT')
                  ->join('bm_search_data e ON a.data_id=e.data_id','LEFT')
                  ->where($where)
                  ->where('b.first_user='.session('user.web_id').' and b.chat_id >0')
                  ->order('lccdc_id desc')
                  ->group('lccdc_id')
                  ->select();
      /**************************/
      $role['role']['state']=0;
      session('role',$role);
      /**************************/
      $this->assign('apply',$res_data);
      $this->display();
    }
    /**
     * 2018-01-29 23:49:14
     * 显示 商家资料申请上传
     */
    public function web_user_shenqing(){
      if(IS_POST){
          $data=$_POST;
         // dump($data);
          $res=M('shenqing')->save($data);
          //dump($res);die;
          session('shenqing',$data);
          $where['state']=1;
          $res_data=M('lccdc')
                      ->alias('a')
                      ->join('bm_chat b ON a.chat_id=b.chat_id','LEFT')
                      ->join('bm_web_user_data c ON a.c_id=c.c_id','LEFT')
                      ->join('bm_shenqing d ON a.cd_id=d.cd_id','LEFT')
                      ->join('bm_search_data e ON a.data_id=e.data_id','LEFT')
                      ->where($where)
                      ->where('a.web_id='.session('user.web_id').' and b.chat_id >0')
                      ->order('lccdc_id desc')
                      ->group('lccdc_id')
                   //  ->fetchsql(true)
                      ->select();
          //dump($res_data);
          $this->assign('apply',$res_data);
          $this->display('Mix/show_chat_list');die;
      }
     $this->assign('msg_data',json_encode($_GET));
     $this->display();

     
    }
    /**
     * 异步文件上传-图片
     */
    /**
     * ajax接受文件
     */
    public function ajax_img_links(){
          if ($_FILES["file"]["size"] < 2000000){
            if ($_FILES["file"]["error"] > 0){
                $msg['code']=2;
                $msg['message']='错误';
              }
            else{
                $msg=D('WebUser')->upload_img('web_user_data');
              }
          }
          else{
            $msg['code']=3;
            $msg['message']='文件过大';
          }
          $this->ajaxReturn($msg);
    }
    /**
     * 异步上存
     * @return [type] [description]
     */
    public function ajax_ht_links(){
          if ($_FILES["file"]["size"] < 2000000){
            if ($_FILES["file"]["error"] > 0){
                $msg['code']=2;
                $msg['message']='错误';
              }
            else{
              $msg=D('WebUser')->upload_img('web_user_data');
              }
          }
          else{
            $msg['code']=3;
            $msg['message']='文件过大';
          }
          $this->ajaxReturn($msg);
    }
    /**
     * 密码重置web
     */
    public function post_from_frg(){
        if(IS_POST){
            $data['web_pass']=$_POST['web_pass'];
            $my_web_user=M('web_user')->where($data)->find();
            if($my_web_user['bind_id']>0){
               $this->success('账号已经处于绑定状态不允许重置',U('Wchat/login'),3);die;
            }
            else{
                M('web_user')->where('web_phone='.$_POST['web_phone'])->save('web_pass','');
                $res=M('web_user')->where('web_phone='.$_POST['web_phone'])->save($data);
                if($res){
                     $this->success('修改成功',U('Wchat/login'),3);die;
                }
                else{
                    $this->success('重置密码失败,请确保手机号码没错',U('Wchat/login'),3);die;
                }
            }
        }
        $this->display('Wchat/post_from_frg');
    }
    /**
     * ajax清空全部session
     */
    public function dest(){
      session_destroy();
      $res=session();
      if(empty($res)){
        $msg['message']='session清空完成';
      }
      $this->ajaxReturn($msg);
    }
    /**
     * 更新客户资料数据
     * @return [type] [description]
     * @DateTime:    [2018-04-02 18:42:18]
     */
    public function save_img(){

      if(IS_AJAX&&IS_POST){
          if(I('post.c_id')&&I('post.add_link')){
             $cid=I('post.c_id');
             $web_user_data=M('web_user_data');
             $link=$web_user_data->where(array('c_id'=>$cid))->getField('link');
             if(strlen($link)==0){
                $link=I('post.add_link');
             }
             else{
                $link=$link.','.I('post.add_link');
             }
             $res=$web_user_data->where(array('c_id'=>$cid))->save(array('link'=>$link));
             if($res){
                $msg['code']='1';
                $msg['message']='追加成功';
                $msg['data']=$res;

             }
             else{
                $msg['code']='2';
                $msg['message']='追加失败';
                $msg['data']=$res;
             }
          }
          else{
            $msg['code']='3';
            $msg['message']='参数不足';
          }
      }
      else{
        $msg['code']='4';
        $msg['message']='请求方式错误';
      }
      $this->ajaxReturn($msg);


    }
}